#include "qupdateprogressdialog.h"
#include "ui_qupdateprogressdialog.h"

#include "../libs/core/qsoftcore.h"
#include "../libs/update/qupdatemanager.h"

QUpdateProgressDialog::QUpdateProgressDialog(QWidget *parent) :
    QBaseDialog(parent),
    ui(new Ui::QUpdateProgressDialog)
{
    ui->setupUi(this);

    connect(QSoftCore::get_core()->update_manager(),SIGNAL(progress(qint64,qint64)),
            this,SLOT(progress(qint64,qint64)));

    connect(QSoftCore::get_core()->update_manager(),SIGNAL(file_finish()),
            this,SLOT(finish()));
}

QUpdateProgressDialog::~QUpdateProgressDialog()
{
    delete ui;
}

void QUpdateProgressDialog::progress(qint64 count, qint64 total)
{
    ui->progressBar->setRange(0,total);
    ui->progressBar->setValue(count);
    QString str;
    str.sprintf("%0.2f%%",count*100.0/total);
    setWindowTitle(str);
    ui->label->setText(str);
}

void QUpdateProgressDialog::finish()
{
    exit(0);
}
